package slice

func Find[T comparable](src []T, dst T) (T, bool) {
	for _, v := range src {
		if dst == v {
			return dst, true
		}
	}
	return dst, false
}

func FindFunc[T any](src []T, match matchFunc[T]) (T, bool) {
	for _, val := range src {
		if match(val) {
			return val, true
		}
	}
	var t T
	return t, false
}

func FindAll[T any](src []T, match matchFunc[T]) []T {
	var res = make([]T, 0, len(src)>>3+1)
	for _, val := range src {
		if match(val) {
			res = append(res, val)
		}
	}
	return res
}
